home *** CD-ROM | disk | FTP | other *** search
- Path: news.atw.fullfeed.com!usenet
- From: sbaierl@sninw.com (Scott J. Baierl)
- Newsgroups: comp.lang.c++
- Subject: Re: Help on DLLs
- Date: Fri, 19 Jan 1996 22:48:00 GMT
- Organization: Schneider National, Inc.
- Message-ID: <4dp778$o7c@ray.atw.fullfeed.com>
- References: <$Eg$ma-0FZ$F078yn@login.dknet.dk>
- NNTP-Posting-Host: sbaierl.atw.fullfeed.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- I don't have a small sample handy, but I thought I'd offer advice on
- one caveat. If you need to return a string, allocate it in your
- Visual Basic application, pass it ByVal to the .DLL and fill the
- buffer in the .DLL. A Visual Basic string is not a pointer to a
- character buffer like in C++.
-
- I've seen people actually return a pointer to a character buffer as
- from within a .DLL to a VB program as a variant. They then try to
- copy the contents of the (unusable) buffer into a Visual Basic string
- using lstrcpy. The problem is that you can't control the lifetime of
- the buffer that was passed to you. If it was allocated on the stack
- in a function call, then it no longer exists. Your pointer is
- invalid.
-
- An alternative would be to use the Visual Basic extensions for C/C++
- to deal directly with VB string descriptors, but then you can only
- call your .DLL function from VB.
-
-
- cronberg@login.dknet.dk (Michell Cronberg) wrote:
-
- > I need some help in programming DLL's i C++
- > (Borland for WIN 3.1) to bee used with Visual
- > Basic.
-
- > Does anyone have a short example of a DLL with
- > functions returning an integer and a string.
-
- > Any help would be highly appreciated. Post or mail.
-
- > Thanks in advance.
-
- > Michell Cronberg
-
-
-
-